package ru.amse.vlassiev.model;

import ru.amse.vlassiev.view.*;
import java.util.*;
import ru.amse.vlassiev.reader.*;

public class Filtrator implements IFiltrator, IListener{
	
	private List<IFilter> myFilter;
	private List<Timer> myTimer;
	
	public Filtrator() {
		myFilter = new LinkedList<IFilter>();
		myTimer = new LinkedList<Timer>();
	}

	public void addFilter(IFilter filter) {
		myFilter.add(filter);
		Timer timer = new Timer();
		myTimer.add(timer);
		timer.schedule(filter.getTask(), (long) filter.getInterval(), (long) filter.getInterval());
	}

	public void newMessage(Map<String, String> message) {
		for (IFilter filter : myFilter) {
			filter.loadNewMessage(message);
		}
	}

	public void removeFilter(IFilter filter) {
		myFilter.remove(filter);
	}
	
	public void removeAllFilters() {
		myFilter = new LinkedList<IFilter>();
		myTimer = new LinkedList<Timer>();
	}
	
	public void addView(IView view) {
		;
	}

}
